<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="utf-8">
    <title>NonPolarGridZone.js - Documentation</title>

    <script src="scripts/prettify/prettify.js"></script>
    <script src="scripts/prettify/lang-css.js"></script>
    <!--[if lt IE 9]>
      <script src="//html5shiv.googlecode.com/svn/trunk/html5.js"></script>
    <![endif]-->
    <link type="text/css" rel="stylesheet" href="styles/prettify.css">
    <link type="text/css" rel="stylesheet" href="styles/jsdoc.css">
</head>
<body>

<input type="checkbox" id="nav-trigger" class="nav-trigger" />
<label for="nav-trigger" class="navicon-button x">
  <div class="navicon"></div>
</label>

<label for="nav-trigger" class="overlay"></label>

<nav>
    <h2><a href="index.html">Home</a></h2><h3>Classes</h3><ul><li><a href="LabelElement.html">LabelElement</a></li><li><a href="module-labeling-utils-GridPolygon.html">GridPolygon</a></li><li><a href="module-mgrs-utils-NonPolarGridZone.html">NonPolarGridZone</a><ul class='methods'><li data-type='method'><a href="module-mgrs-utils-NonPolarGridZone.html#toPolygon">toPolygon</a></li><li data-type='method'><a href="module-mgrs-utils-NonPolarGridZone.html#toPolyline">toPolyline</a></li></ul></li><li><a href="module-mgrs-utils-VisibleGridZone.html">VisibleGridZone</a><ul class='methods'><li data-type='method'><a href="module-mgrs-utils-VisibleGridZone.html#getCenterLabel">getCenterLabel</a></li><li data-type='method'><a href="module-mgrs-utils-VisibleGridZone.html#getLabels">getLabels</a></li></ul></li></ul><h3>Modules</h3><ul><li><a href="module-constants.html">constants</a></li><li><a href="module-geometry-utils.html">geometry-utils</a><ul class='methods'><li data-type='method'><a href="module-geometry-utils.html#~extentToPolygon">extentToPolygon</a></li><li data-type='method'><a href="module-geometry-utils.html#~pointToGeographic">pointToGeographic</a></li><li data-type='method'><a href="module-geometry-utils.html#~polygonToPolyline">polygonToPolyline</a></li><li data-type='method'><a href="module-geometry-utils.html#~toGeographic">toGeographic</a></li><li data-type='method'><a href="module-geometry-utils.html#~toWebMercator">toWebMercator</a></li></ul></li><li><a href="module-labeling-utils.html">labeling-utils</a><ul class='methods'><li data-type='method'><a href="module-labeling-utils.html#~distanceFromMapEdge">distanceFromMapEdge</a></li><li data-type='method'><a href="module-labeling-utils.html#~getScreenSize">getScreenSize</a></li><li data-type='method'><a href="module-labeling-utils.html#~getWidthOfText">getWidthOfText</a></li><li data-type='method'><a href="module-labeling-utils.html#~padZero">padZero</a></li><li data-type='method'><a href="module-labeling-utils.html#~screenDistanceBetweenPoints">screenDistanceBetweenPoints</a></li></ul></li><li><a href="module-mgrs-utils.html">mgrs-utils</a><ul class='methods'><li data-type='method'><a href="module-mgrs-utils.html#~getInterval">getInterval</a></li><li data-type='method'><a href="module-mgrs-utils.html#~handle100kGrids">handle100kGrids</a></li><li data-type='method'><a href="module-mgrs-utils.html#~handleIntervals">handleIntervals</a></li><li data-type='method'><a href="module-mgrs-utils.html#~handleZonePolygon">handleZonePolygon</a></li><li data-type='method'><a href="module-mgrs-utils.html#~processZonePolygons">processZonePolygons</a></li><li data-type='method'><a href="module-mgrs-utils.html#~zonesFromExtent">zonesFromExtent</a></li></ul></li></ul><h3>Externals</h3><ul><li><a href="external-Color.html">Color</a></li><li><a href="external-Extent.html">Extent</a></li><li><a href="external-Font.html">Font</a></li><li><a href="external-Geometry.html">Geometry</a></li><li><a href="external-Graphic.html">Graphic</a></li><li><a href="external-GraphicsLayer.html">GraphicsLayer</a></li><li><a href="external-Map.html">Map</a></li><li><a href="external-Point.html">Point</a></li><li><a href="external-Polygon.html">Polygon</a></li><li><a href="external-Polyline.html">Polyline</a></li><li><a href="external-SpatialReference.html">SpatialReference</a></li><li><a href="external-TextSymbol.html">TextSymbol</a></li></ul>
</nav>

<div id="main">
    
    <h1 class="page-title">NonPolarGridZone.js</h1>
    

    



    
    <section>
        <article>
            <pre class="prettyprint source linenums"><code>/**
 *  @fileOverview Contains the NonPolarGridZone class used by MGRS GridOverlay widgets.
 *  @author Esri
 */

define([
  "dojo/_base/declare",
  "./constants",
  "esri/geometry/Polygon",
  "esri/geometry/Extent"
], function(
  declare,
  constants,
  Polygon,
  Extent
) {

  /**
   * An object that contains arguments used during NonPolarGridZone construction
   * @typedef {Object} module:mgrs-utils~NonPolarGridZoneArguments
   * @property {String} properties.id       The MGRS grid zone ID (e.g. "12S")
   * @property {Number} properties.xmin     The minimum longitude of the grid zone (-180 => 174)
   * @property {Number} properties.ymin     The minimum latitude of the grid zone (-80 => 72)
   * @property {Number} properties.xmax     The maximum longitude of the grid zone (-174 => 180)
   * @property {Number} properties.ymax     The maximum latitude of the grid zone (-72 => 84)
   * @property {external:SpatialReference} [properties.spatialReference={wkid: 4326}]   The spatial referencence object
   */

  /**
   * @class module:mgrs-utils~NonPolarGridZone
   * @classdesc Contains the properties of a non-polar MGRS grid zone, as defined in the MGRS definition.
   *
   * @constructor
   * @param {module:mgrs-utils~NonPolarGridZoneArguments} args   The NonPolarGridZone constructor arguments object
   *
   * @example
   * var nonPolarGridZoneArgs = {
   *   xmin: -114,
   *   ymin: 32,
   *   xmax: -108,
   *   ymax: 40,
   *   id: "12S"
   * }
   *
   * // gridZone will be an object equivalent to:
   * //   {
   * //      "id": "12S",
   * //      "utmZone": 12,
   * //      "latitudeZone": "S",
   * //      "extent": {
   * //          "type": "extent",
   * //          "xmin": -114,
   * //          "ymin": 32,
   * //          "xmax": -108,
   * //          "ymax": 40,
   * //          "spatialReference": {"wkid": 4326}
   * //      }
   * //   }
   * var gridZone = new NonPolarGridZone(nonPolarGridZoneArgs);
   */
  return declare(null, /** @lends module:mgrs-utils~NonPolarGridZone# */ {

    /** The extent of the grid zone
     * @type {external:Extent}
     */
    "extent": null,

    /** The MGRS grid zone ID (or label; e.g. "12S")
     * @type {String}
     */
    "id": null,

    /** The UTM longitude zone (usually 6° wide)
     * @type {Number}
     */
    "utmZone": null,

    /** The latitude zone (usually 8° tall)
     * @type {String}
     */
    "latitudeZone": null,

    /** An array of rings, used to construct a polygon from the NonPolarGridZone
     * @type {Number[][][]}
     * @private
     */
    "_rings": [],

    constructor: function(args) {
      var lowerLeftCorner, lowerRightCorner, upperRightCorner, upperLeftCorner;

      // parse and set the UTM zone and latitude zone from the id (i.e. "12S" would parse to ['12', 'S'])
      var parseId = args.id.match(/(\d+)|([A-Za-z]+)/g);
      this.id = args.id;
      this.utmZone = parseId[0] * 1;
      this.latitudeZone = parseId[1];

      // create the extent object for this instance
      this.extent = new Extent({
        "xmin": args.xmin,
        "ymin": args.ymin,
        "xmax": args.xmax,
        "ymax": args.ymax,
        "spatialReference": args.spatialReference || {wkid: 4326}
      });

      // Construct rings to be used later to construct a polygon from a NonPolarGridZone instance.
      // Don't create the polygon now, because the same instance is reused as the map is in wraparound mode.
      // Thus, the 'toPolygon' method is used for retreiving a polygon when needed
      lowerLeftCorner = [this.extent.xmin, this.extent.ymin];
      lowerRightCorner = [this.extent.xmax, this.extent.ymin];
      upperRightCorner = [this.extent.xmax, this.extent.ymax];
      upperLeftCorner = [this.extent.xmin, this.extent.ymax];
      this._rings = [[
        lowerLeftCorner,
        lowerRightCorner,
        upperRightCorner,
        upperLeftCorner,
        lowerLeftCorner
       ]];
    },

    /**
     * Convert to a polygon
     * @param  {Number} [offsetX=0] Instruction to return a non-normalized polygon (i.e. falls outside the normal world extent). Used for drawing grids when a map is in wraparound mode
     *              NOTE: Specify a negative integer for west of W180° OR a positive integer for east of E180°
     * @return {external:Polygon} The zone, represented as a Polygon
     */
    toPolygon: function(offsetX) {
      var rings = JSON.parse(JSON.stringify(this._rings));

      // Shift the rings left/right to match the x-offset (i.e. how many increments left or right
      // of the dateline, to support wraparound maps)
      if (offsetX) {
        for (var i = 0; i &lt; rings[0].length; i++) { // modify the zone paths for x_offset
          rings[0][i][0] += offsetX * constants.GEOGRAPHIC_360;
        }
      }

      // build and return the polygon
      return new Polygon({
        "rings": rings,
        "spatialReference": this.spatialReference
      });
    },

    /**
     * Convert to a polyline
     * @param  {Number} [offsetX=0] Instruction to return a non-normalized polyline (i.e. falls outside the normal world extent). Used for drawing grids when a map is in wraparound mode
     *              NOTE: Specify a negative integer for west of W180° OR a positive integer for east of E180°
     * @return {external:Polyline} The zone, represented as a Polyline
     */
    toPolyline: function(offsetX) {
      var paths = JSON.parse(JSON.stringify(this._rings));

      // Shift the rings left/right to match the x-offset (i.e. how many increments left or right
      // of the dateline, to support wraparound maps)
      if (offsetX) {
        for (var i = 0; i &lt; paths[0].length; i++) { // modify the zone paths for x_offset
          paths[0][i][0] += offsetX * constants.GEOGRAPHIC_360;
        }
      }

      // build and return the polyline
      return new Polyline({
        "paths": rings,
        "spatialReference": this.spatialReference
      });
    }

  });
});</code></pre>
        </article>
    </section>




</div>

<br class="clear">

<footer>
    Documentation generated by <a href="https://github.com/jsdoc3/jsdoc">JSDoc 3.4.0</a> using the <a href="https://github.com/clenemt/docdash">docdash</a> theme.
</footer>

<script>prettyPrint();</script>
<script src="scripts/linenumber.js"></script>
</body>
</html>
